<?php
/**
 * Programmatic model for an SQL Value
 */
class SQLValue {
	private $value;
	
	/**
	 * Sets a value as SQL value
	 * @param number|string $value
	 */
	public function __construct($value) {
		$this->value = $value;
	}
	
	/**
	 * Converts value to string. Escapes and surrounds with quotes if necessary.
	 * @return number|string
	 */
	public function toString() {
		if(is_numeric($this->value)) return $this->value;
		else if(is_bool($this->value)) return ($this->value?1:0);
		else return "'".str_replace("'","''",$this->value)."'";
	}
}